set scheme s1color

use repeated_cross_section, clear

// Placebo muslim indicator (Laos, Vietnam or Cambodia)
gen muslim=(paiperc=="09")

// cluster variable
egen pbpl=group(paiperc)

// aggregate cohorts
gen cohort=1980 if birthyear==1980|birthyear==1981
replace cohort=1982 if birthyear==1982|birthyear==1983
replace cohort=1984 if birthyear==1984|birthyear==1985
replace cohort=1986 if birthyear==1986|birthyear==1987
replace cohort=1988 if birthyear==1988|birthyear==1989
replace cohort=1990 if birthyear==1990|birthyear==1991 
replace cohort=1992 if birthyear==1992|birthyear==1993



local sample if pnai28=="10"  & female==1
local cl pbpl
reg secondary i.ag i.surveyr `sample', cluster(`cl')   
predict resid, res
local var resid
collapse (mean) `var' (count) personid `sample', by(cohort muslim)

******************************************
expand 2
replace cohort = . if _n>(_N/2)
recode muslim (1=0) (0=1) if cohort==.
********************************************
twoway scatter `var'  cohort [aweight=personid] if muslim==1, msymbol(circle) mcolor(cranberry) legend(label(1 "Born in Laos, Vietnam or Cambodia") label(2 "Others")) ///
 ||  scatter `var'  cohort [aweight=personid] if muslim==0, msymbol(circle_hollow) mcolor(dknavy) xline(1986, lcolor(gs10)) ///
 xtitle("Year of birth") ytitle("Completed secondary education | X")
